<?
$ds = clone GET();

if ( $ds->exists( 'h' ) && $ds->isEmpty( 'h' ) == false )
{
	$test = unserialize( base64_decode( $ds->h ) );
	if ( is_array( $test ) )
	{
	    $ds->set( $test );
		$ds->merge( GET() );
	}
}
$form = load_form( 'generate/controller' );
$form->processor( URL( 'generate/controller' ) );
$form->ds( clone $ds );
echo $form->render();

if ( $ds->dataPresent )
{
	$ds->setVar( 'modelVarName', '$' . lcfirst( str_replace( ' ', '', ucwords( str_replace( '_', ' ', basename( $ds->model ) ) ) ) . 'Model' ) );
	$ds->setVar( 'model_name', basename( $ds->model ) );

	$ds->setVar( 'extraJs', array() );
	$ds->setVar( 'extraCss', array() );

	if ( ! $ds->isEmpty( 'extra_js' ) )
	{
		$ds->setVar( 'extraJs', explode( "\n", $ds->extra_js ) );
	}

	if ( ! $ds->isEmpty( 'extra_css' ) )
	{
		$ds->setVar( 'extraCss', explode( "\n", $ds->extra_css ) );
	}

	ob_start();
	include view( 'generate/controller' );

	$code = htmlentities( ob_get_clean() );
	?><textarea style="font-family: courier; width: 100%; height:100%;"><?= $code; ?></textarea><?php
}
else
{
	
}